package com.example.spzx.controller;

import cn.hutool.db.PageResult;
import com.example.spzx.Service.BrandService;
import com.example.spzx.model.entity.product.Brand;
import com.example.spzx.model.vo.common.Result;
import com.example.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/brand")
public class BrandController {
    @Resource
    private BrandService brandService;
    @GetMapping("/list")
    public Result<Brand> list(Integer pageNum, Integer pageSize){
        PageInfo<Brand> list=brandService.getlist(pageNum,pageSize);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/save")
    public Result<Brand> save(@RequestBody Brand brand){
        brandService.save(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @PutMapping("/updateById")
    public Result<Brand> updateById(@RequestBody Brand brand){
        brandService.update(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @DeleteMapping("/deleteById/{id}")
    public Result<Brand> deleteById(@PathVariable("id") Integer id){
        brandService.delete(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/all")
    public Result<Brand> all(){
        List<Brand> list=brandService.getall();
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }


}
